{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content"> 
				<div class="row row-lg"> 
					<div class="col-sm-12"> 
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">被保人姓名</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="insured_name" placeholder="被保人姓名" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">被保人类型</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="insured_type" placeholder="被保人类型" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">被保人证件号码</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="insured_card_no" placeholder="被保人证件号码" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">被保人证件类型</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="insured_card_type" placeholder="被保人证件类型" />
								</div>
							</div>
							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						{if condition="in_array('admin/Insurance.InsurancePolicy/add',session('admin.nodes')) || session('admin.role_id') eq 1"}
						<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
						<i class="fa fa-plus"></i>&nbsp;添加
						</button>
						{/if}
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人姓名', field: 'insured_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人类型', field: 'insured_type', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人证件号码', field: 'insured_card_no', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人证件类型', field: 'insured_card_type', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人证件有效期', field: 'insured_card_valid', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人性别', field: 'insured_gender', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人电子邮件', field: 'insured_email', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '被保人手机', field: 'insured_mobile', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '投保人', field: 'userid', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '与投保人关系', field: 'with_holder_relation', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '与投保人关系说明', field: 'with_holder_relation_dec', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '身份证件正面扫描件储存地址', field: 'card_obverse_url', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.card_obverse_urlFormatter},
 			{title: '身份证件反面扫描件储存地址', field: 'card_reverse_url', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.card_reverse_urlFormatter},
 			{title: '保单名称', field: 'policy_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '该订单所属保险公司简称', field: 'ic_short_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '产品id', field: 'product_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '对应保险公司id', field: 'ic_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '商业险对应保险公司Code', field: 'ic_code', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '产品类别', field: 'product_category', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '起保日期', field: 'begin_date', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.begin_dateFormatter},
 			{title: '是否同投保人', field: 'is_holder', visible: true, align: 'center', valign: 'middle',sortable: true},
 		];
 	};

	CodeGoods.card_obverse_urlFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";	
		}
	}

	CodeGoods.card_reverse_urlFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";	
		}
	}

	CodeGoods.begin_dateFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value,'Y-m-d H:i:s');	
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['insured_name'] = $("#insured_name").val();
		queryData['insured_type'] = $("#insured_type").val();
		queryData['insured_card_no'] = $("#insured_card_no").val();
		queryData['insured_card_type'] = $("#insured_card_type").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Insurance.InsurancePolicy/add'+url});
		this.layerIndex = index;
		if(!IsPC()){layer.full(index)}
	}


	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Insurance.InsurancePolicy/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}